package com.jiantong.lawEnforcing.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.terminus.common.utils.JsonMapper;
import lombok.Data;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * 当场处罚决定书
 * Created by mz03 on 2017/8/8.
 */
@Data
public class SimplenessCases implements Serializable {
    private static final long serialVersionUID = -7687426433692480570L;
    private static final ObjectMapper objectMapper= JsonMapper.nonEmptyMapper().getMapper();


    /**
     * 主键id
     */
    private Long id;

    /**
     * 案件登记id
     */
    private Long cases_basic_id;

    /**
     * 违法事实
     */
    private String incident_description;

    /**
     * 处罚依据以及内容
     */
    private String punishment;

    /**
     * 告知截止纠正时间
     */
    private Date inform_date;

    /**
     * 告知交罚款的地点
     */
    private String inform_site;

    /**
     * 可申请复议的农业局名
     */
    private String inform_agricultural;

    /**
     * 可提起诉讼的人民法院
     */
    private String inform_court;

    /**
     * 执法人名字
     */
    private String enforcement_name;

    /**
     * 执法人证件号
     */
    private String enforcement_certificate;


    /**
     * 处罚证书照片 不存数据库
     */
    private Map<String , String> picture_map;

    /**
     * 处罚证书照片
     */
    @JsonIgnore
    private String picture_json;


    public void setPicture_map(Map<String,String> picture_map){
        this.picture_map = picture_map;
        if(picture_map == null || picture_map.isEmpty()){
            this.picture_json = null;
        }else {
            try {
                this.picture_json = objectMapper.writeValueAsString(picture_map);
            } catch (JsonProcessingException e) {
                //ignore this fuck IOException
            }
        }
    }


    public void setPicture_json(String picture_json){
        this.picture_json = picture_json;

        if(Strings.isNullOrEmpty(picture_json)){
            this.picture_map = Maps.newHashMap();
        }else {
            try {
                this.picture_map = objectMapper.readValue(picture_json, new TypeReference<Map<String , String>>() {});
            } catch (IOException e) {
                //ignore this fuck IOException
            }
        }
    }


    /**
     * 状态: 1 待处理; 2 已处理;
     */
    private Integer status;

    /**
     * 案由
     */
    private String cause_action ;

    /**
     * 案件来源
     */
    private Integer cases_source;

    /**
     * 当事人类型
     */
    private Integer parties_type;

    /**
     * 当事人名字
     */
    private String parties_name;

    /**
     * 删除标志 1:正常; -1:删除
     */
    private Integer delete_flag;

    /**
     * 创建时间
     */
    private Date created_at;

    /**
     * 更新时间
     */
    private Date update_at;

}
